/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.vng.zing.zprofilefrontend.servers;

import com.vng.zing.jettyserver.WebServers;
import com.vng.zing.zprofilefrontend.handlers.AjaxChangePasswordHandler;
import com.vng.zing.zprofilefrontend.handlers.AjaxChangeStatusHandler;
import com.vng.zing.zprofilefrontend.handlers.AjaxCreateHandler;
import com.vng.zing.zprofilefrontend.handlers.AjaxLoginHandler;
import com.vng.zing.zprofilefrontend.handlers.AjaxUpdateHandler;
import com.vng.zing.zprofilefrontend.handlers.ChangePasswordHandler;
import com.vng.zing.zprofilefrontend.handlers.CreateHandler;
import com.vng.zing.zprofilefrontend.handlers.FacebookLogInCallbackHandler;
import com.vng.zing.zprofilefrontend.handlers.InfoHandler;
import com.vng.zing.zprofilefrontend.handlers.LogInHandler;
import com.vng.zing.zprofilefrontend.handlers.LogOutHandler;
import com.vng.zing.zprofilefrontend.handlers.ProfileListHandler;
import com.vng.zing.zprofilefrontend.handlers.UpdateHandler;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;

/**
 *
 * @author namnq
 */
public class HServers {
    public boolean setupAndStart() {
       
       
        WebServers servers = new WebServers("zprofilefrontend");
        ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
      //  handler.addServlet(RoutingHandler.class, "/*");
       // handler.addFilter(FilterHandler.class, "/*", EnumSet.of(DispatcherType.REQUEST));

        handler.addServlet(LogInHandler.class, "/*");
        handler.addServlet(CreateHandler.class, "/create");
        handler.addServlet(InfoHandler.class, "/info");
        handler.addServlet(UpdateHandler.class, "/update");
        handler.addServlet(ChangePasswordHandler.class, "/changePassword");
        handler.addServlet(AjaxCreateHandler.class, "/ajaxCreate");
        handler.addServlet(AjaxLoginHandler.class, "/ajaxLogin");
        handler.addServlet(LogOutHandler.class, "/logout");
        handler.addServlet(AjaxChangePasswordHandler.class, "/ajaxChangePassword");
        handler.addServlet(AjaxUpdateHandler.class, "/ajaxUpdate");
        handler.addServlet(ProfileListHandler.class, "/list");
        handler.addServlet(AjaxChangeStatusHandler.class, "/ajaxChangesStatus");
        handler.addServlet(FacebookLogInCallbackHandler.class, "/fblogin");

        ResourceHandler resource_handler = new ResourceHandler();
        resource_handler.setResourceBase("././resources");

        ContextHandler context0 = new ContextHandler();
        context0.setContextPath("/resources");
        context0.setHandler(resource_handler);

        HandlerList handlerList = new HandlerList();
        handlerList.addHandler(context0);
        handlerList.addHandler(handler);
        

        servers.setup(handlerList);
        return servers.start();
    }
}
